def is_prime(x):
    for i in range(2, (x//2)+1):
        if x % i == 0:
            return False
    return True



number = input("Введите четырехзначное натуральное число")
answer = 0
if len(number) < 4:
    print(0)
else:
    for i in range(4):
        if is_prime(int(number[i])) and int(number[i]) > answer:
            answer = int(number[i])
    helper = ''
    for i in range(3):
        helper += number[i] + number[i+1]
        if is_prime(int(helper)) and int(helper) > answer:
            answer = int(helper)
        helper = ''
    for i in range(2):
        helper += number[i] + number[i + 1] + number[i + 2]
        if is_prime(int(helper)) and int(helper) > answer:
            answer = int(helper)
        helper = ''
    if is_prime(int(number)) and int(number) > answer:
        answer = int(number)
    if answer == 0:
        print(0)
    else:
        print(answer)
